package com.farina.tracescleaner.tasks;

import java.io.File;

import android.content.Context;
import android.os.Environment;

public class DeleteWhatsAppDataTask{

	Context context;


	public DeleteWhatsAppDataTask(Context context) {
		this.context=context;
	}

	public void delete() {
		
		try{
			clearApplicationData();
		}
		catch(Exception e){}		
	}
	
    public void clearApplicationData() {
        File cache = Environment.getExternalStorageDirectory();
        File appDir = new File(cache.getAbsolutePath()+"/WhatsApp");
        if (appDir.exists()) {
            String[] children = appDir.list();
            for (String s : children) {
                if (!s.equals("lib")) {
                    deleteDir(new File(appDir, s));
                    
                }
            }
        }
    }

    public static boolean deleteDir(File dir) {
        if (dir != null && dir.isDirectory()) {
            String[] children = dir.list();
            for (int i = 0; i < children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }

        return dir.delete();
    }

}
